package com.bsoft.gol.hbs.service.impl;

import ctd.spring.boot.annotation.SsdevService;
import ctd.util.annotation.RpcService;
import com.bsoft.gol.hbs.dao.BaseActionRecordDAO;
import hcn.base.BaseActionRecord;
import org.springframework.beans.factory.annotation.Autowired;
import com.bsoft.gol.hbs.utils.CommonUtils;

import java.util.List;

/**
 * 基础交互记录服务
 */
@SsdevService("baseActionRecordService")
public class BaseActionRecordService {

    @Autowired
    private BaseActionRecordDAO baseActionRecordDAO;

    /**
     * 保存操作记录
     */
    public void saveAction(BaseActionRecord record) {
        baseActionRecordDAO.save(record);
    }

    /**
     * 删除操作记录
     *
     * @author linyi
     * @date 2021/11/16 14:02
     * @param businessId 业务id
     * @param businessType 业务类型 news activity
     * @param action 互动操作类型
     * @param userId 用户id
     */
    public void removeAction(String businessId, String businessType, String action, String userId) {
        baseActionRecordDAO.deleteByBizKey(businessId, businessType, action, userId);
    }

    /**
     * 根据索引获取一条记录
     */
    @RpcService
    public BaseActionRecord getByBizKey(String businessId, String businessType, String action, String userId){
        List<BaseActionRecord> byBizKey = baseActionRecordDAO.findByBizKey(businessId, businessType, action, userId);
        if(CommonUtils.isNotEmpty(byBizKey)){
            return byBizKey.get(0);
        }
        return null;
    }


    /**
     * 根据参数获取业务id列表
     */
    public List<String> getBusinessIdList(String businessType, String action, String userId){
        return baseActionRecordDAO.findBusinessIdList(businessType, action, userId);
    }



}
